home *** CD-ROM | disk | FTP | other *** search
- Path: engnews2.Eng.Sun.COM!usenet
- From: nitin@more.eng.sun.com (Nitin More [CONTRACTOR])
- Newsgroups: comp.lang.c++
- Subject: Re: OO design issue
- Date: 09 Jan 1996 18:41:52 GMT
- Organization: SunSoft
- Message-ID: <NITIN.96Jan9104152@more.eng.sun.com>
- References: <4ctp93$2gu@news.kth.se>
- NNTP-Posting-Host: more.eng.sun.com
- In-reply-to: Anders Olsson's message of 9 Jan 1996 13:06:43 GMT
-
-
- I would include vector of Nodes in the Triangle class rather than having
- indexes stored there. Then you don't need to have class TrianglesAndNodes and
- whenever you have an handle on the Triangle instance, you immediately have
- access to instances of its Nodes.
-
- Triangle is made up of 3 Nodes so let the Triangle class keep that
- information. Don't invent another class (TrianglesAndNodes) to keep track of
- associations.
-
- -Nitin
-
-
- In article <4ctp93$2gu@news.kth.se> Anders Olsson <aolsson@struct.kth.se> writes:
-
- > From: Anders Olsson <aolsson@struct.kth.se>
- > Newsgroups: comp.lang.c++
- > Date: 9 Jan 1996 13:06:43 GMT
- >
- > I accidently posted the last message before I got to my point
- > (never write messages in a window where you have a "Post it" keycombination:-)
- >
- > I'll try again:
- >
- > I have some questions about how to design relations between a class and
- > its member classes.
- >
- > I can simplify my problem to the following three classes:
- >
- > class Node
- > {
- > public:
- > double GetXCoordinate();
- > private:
- > double XCoordinate;
- > };
- >
- > class Triangle
- > {
- > public:
- > double CalculateArea();
- > private:
- > int nNodeIndex[3]; // Index into node vector
- > };
- >
- > class TrianglesAndNodes
- > {
- > double GetXCoordinate(int NodeNr);
- > private:
- > vector<Node> NodeVector;
- > vector<Triangle> TriangleVector;
- > };
- >
- > The TrianglesAndNodes class is a world of nodes and triangles, and it contains two vectors of Node:s, and Triangle:s.
- > The Triangle has a method that calculates its own area.
- > However, it has only information about the index of the nodes it is connected to.
- > So to get the necessary coordinates the Triangle instance can use the GetXCoordinate method,
- > defined in TrianglesAndNodes. The problem is how to reach the TrianglesAndNodes instance
- > from the Triangle instance.
- > Is there a recommended way to do this is?
- >
- > ---
- > Anders Olsson
- > Stockholm, Sweden
- --
- ----------------------------------------------------------------------
- Nitin More
- SunSoft, Bldg 16 Off: (415) 786 7109
- Menlo Park, CA Fax: (415) 786 7957 e-mail: nitin@more.eng.sun.com
- ----------------------------------------------------------------------
-